package com.example.light.web.system.dao;

import com.example.light.web.system.entity.CuserRole;
import com.example.light.web.system.entity.Department;
import com.example.light.web.system.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CuserRoleMapper {
    /**
     *
     * 功能描述: 用户管理信息查询（总）
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @Results(id="CUserResults",value = {
            @Result(property = "cuserRoleName",column = "role_name"),
            @Result(property = "cuserId",column = "user_id"),
            @Result(property = "cuserName",column = "user_name"),
            @Result(property = "cuserDeptName",column = "dept_name"),
            @Result(property = "curserTime",column = "user_manipulate_time")
    })
    @Select("SELECT role_name,user_id,user_name,dept_name,user_manipulate_time " +
            "FROM role,user_role,`user`,department " +
            "WHERE `user`.user_id=user_role.use_id " +
            "AND user_role.role_id = role.role_id AND department.dept_id=`user`.dept_id")
    public List<CuserRole> QueryAll();

    
    /**
     *
     * 功能描述: 角色列表查询
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @Results(id="RoleResults",value = {
            @Result(property = "roleId",column = "role_id"),
            @Result(property = "roleName",column = "role_name"),
            @Result(property = "createTime",column = "role_create_time"),
            @Result(property = "roleMemo",column = "role_memo")
    })
    @Select("select role_name from role")
    public  List<Role> rolelist();
    
    
    /**
     *
     * 功能描述: 部门列表查询
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @Results(id="DeptResults",value = {
            @Result(property = "deptId",column = "dept_id"),
            @Result(property = "deptName",column = "dept_name"),
            @Result(property = "deptMemo",column = "dept_description"),
            @Result(property = "deptPeople",column = "dept_people"),
            @Result(property = "deptTel",column = "dept_contact"),
            @Result(property = "createTime",column = "dept_create_time")
    })
    @Select("select dept_name from department")
    public List<Department> deptlist();
    
    /**
     *
     * 功能描述: 按角色名查找用户信息
     *
     * @param:
     * @return: 
     * @auther: 
     * @date:  
     */
    @ResultMap("CUserResults")
    @Select("SELECT role_name,user_id,user_name,dept_name,user_manipulate_time " +
            "FROM role,user_role,`user`,department " +
            "WHERE `user`.user_id=user_role.use_id " +
            "AND user_role.role_id = role.role_id AND department.dept_id=`user`.dept_id " +
            "AND role.role_name=#{rolename}")
    public List<CuserRole> ChoseRole(String rolename);
    
    /**
     *
     * 功能描述: 按用户名模糊查询
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @ResultMap("CUserResults")
    @Select("SELECT role_name,user_id,user_name,dept_name,user_manipulate_time " +
            "FROM role,user_role,`user`,department " +
            "WHERE `user`.user_id=user_role.use_id " +
            "AND user_role.role_id = role.role_id AND department.dept_id=`user`.dept_id " +
            "AND `user`.user_name like #{name}")
    public List<CuserRole> selectByname(String name);
}
